package com.wlhse.controller;

import com.wlhse.entity.ProblemFactorPojo;
import com.wlhse.service.ProblemFactorService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController("ProblemFactorController")
@RequestMapping("/api/v1")
//问题类别
public class ProblemFactorController {

    @Resource
    private ProblemFactorService service;

    //新增
    @RequestMapping(value = "/problem_factor", method = RequestMethod.POST, produces = "application/json; charset=utf-8")
    public String addProblemFactor(@RequestBody(required = false) ProblemFactorPojo problemFactorPojo) {
        return service.saveProblemFactor(problemFactorPojo);
    }

    //删除 by TaskAndProcessCode
    @RequestMapping(value = "/problem_factor", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8")
    public String deleteProblemFactor(@RequestBody(required = false) ProblemFactorPojo problemFactorPojo) {
        return service.removeProblemFactor(problemFactorPojo.getProblemFactorCode());
    }

    //更新
    @RequestMapping(value = "/problem_factor/{id}", method = RequestMethod.PUT, produces = "application/json; charset=utf-8")
    public String UpdateProblemFactor(@PathVariable int id, @RequestBody(required = false) ProblemFactorPojo problemFactorPojo) {
        problemFactorPojo.setProblemFactorID(id);
        return service.updateProblemFactor(problemFactorPojo);
    }

    @RequestMapping(value = "/problem_factor/tree", method = RequestMethod.GET, produces = "application/json; charset=utf-8")
    public String getChirdren() {
        return service.getProblemFactorTree();
    }
}
